package oldFiles;
import lejos.nxt.Button;
import lejos.nxt.LightSensor;
import lejos.nxt.SensorPort;
import lejos.nxt.addon.*;


public class RobotRace {	
	
	public RobotRace() {}
	
	private static final int GREENTHRESHOLD = 200;
	private static final int WHITETHRESHOLD = 420;
	
	private static final int SAMPLE_INTERVAL = 15;
		
	public enum color {BLACK, WHITE, GREEN};
	public enum direction {LEFT, RIGHT, FORWARD, ROUNDLEFT, ROUNDRIGHT};
	public static LightSensor s = new LightSensor(SensorPort.S3, true);  
	
	public static void main(String[] args) {

		direction currentDirection = direction.LEFT;
		RaceCar.turnRight();
		
		color currentColor, lastColor;
		
		currentColor = color.WHITE;
		lastColor = color.BLACK;
		
		while (! Button.ESCAPE.isPressed()) {
			
			currentColor = getColor();
			
			switch(currentDirection) {
				case FORWARD:
					break;
				case LEFT:
					if (lastColor == color.BLACK && currentColor == color.WHITE) {
						RaceCar.turnRight();
						currentDirection = direction.RIGHT;
						
					}
					break;
				case RIGHT:
					if (lastColor == color.BLACK && currentColor == color.WHITE) {
						RaceCar.turnLeft();
						currentDirection = direction.LEFT;
					}
					break;
				case ROUNDLEFT:
					break;
				case ROUNDRIGHT:
					break;
				default:
					break;
			
			}
			
			lastColor = currentColor;
			
		}
	}
	
	private static color getColor() {
		int readValue = s.readNormalizedValue();	
		if (readValue < GREENTHRESHOLD) return color.GREEN;
		else if (readValue > WHITETHRESHOLD) return color.WHITE;
		else return color.BLACK;
	}
	
		
}
